<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #main{
            width:1000px;
            margin:auto;
        }
        #smallpic{
            height:120px; 
        }
        img{
            float:left; 
            margin-right:10px; 
            margin-bottom:10px;
        }
        #smallpic img:hover{
            cursor:pointer;
        }
        .pb{
            border:2px solid red;
        }
    </style>
</head>
<body>
    <div id="main">
        <div id="smallpic">
            <img class="test" src="images/1.jpg"  width="180" height="100" />
            <img class="test" src="images/2.jpg"  width="180" height="100"/>
            <img class="test" src="images/3.jpg"  width="180" height="100"/>
            <img class="test" src="images/4.jpg"  width="180" height="100"/>
            <img class="test" src="images/5.jpg"  width="180" height="100"/>
        </div>
        <div>
            <img src="images/0.jpg" id="bigpic"/></div>
        </div>
</body>
<script>
    //图片的切换
    var small = document.getElementById("smallpic");
    var imgList = document.getElementsByTagName("img");
    var big = document.getElementById("bigpic");
    for(var i = 0;i <= imgList.length;i++){
        imgList[i].onclick = function(){
            // for(var j = 0;j <= imgList.length;j++){
            //     var classStr = imgList[j].getAttribute("class");
            //     var classArr = classStr.split(" ");
            //     if(classArr.indexOf("pb") >= 0){
            //         var index = classArr.indexOf("pb");
            //         classArr.splice(index,1);
            //         var str = classArr.join(" ");
            //         imgList[j].className = str;
            //     }
            for(var i = 0; i < imgList.length; i++) {
                 if(imgList[i].hasAttribute("class")) {
                    imgList[i].removeAttribute("class");
                 }
                 else{
                    continue;//结束本次循环
                }
             }
            //切换大图的src
            var imgSrc = this.src;//this.getAttribute("src");
            big.setAttribute("src", imgSrc);

            this.setAttribute("class","pb");//this.className = "pb";
            this.setAttribute("index", 1);
        }
    }
</script>
</html>